<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
/**
 +------------------------------------------------------------------------------
 * 客服系统-内部接口(公用)
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2014-8-13
 +------------------------------------------------------------------------------
 */
namespace Admin\Controller;

class ServiceApiController extends AdminController {
	
	
	/**
	 * @todo 获取省份list
	 * @author PHP@妖孽<dino_ma@163.com>
	 */
	public function getProvinceList(){
		$this->ajaxReturn(D('Admin/Area','Service')->getProvinceList());
	}
	
	/**
	 * @todo 获取省份下的城市
	 * @param int province_id 省份id
	 * @author PHP@妖孽<dino_ma@163.com>
	 */
	public function getProvinceCityList($province_id){
		$this->ajaxReturn(D('Admin/Area','Service')->getProvinceCityList($province_id));
	}
	
	/**
	 * @todo 获取城市下的行政区
	 * @param int city_id 城市id
	 * @author PHP@妖孽<dino_ma@163.com>
	 */
	public function getCityWard($city_id){
		$this->ajaxReturn(D('Admin/Area','Service')->getCityWard($city_id));
	}
	
	/**
	 * @todo 获取行政区下的小区
	 * @param int ward_id 行政区id
	 * @author PHP@妖孽<dino_ma@163.com>
	 */
	public function getWardVillage($ward_id){
		$this->ajaxReturn(D('Admin/Area','Service')->getWardVillage($ward_id));
	}
	
	/**
	 * @todo 返回所有商户下的所有店铺
	 * @return array
	 * @author fzh <fanzhaohai@hrbjjhh.com>
	 */
	public function getShopList($merchant_id){
	    $this->ajaxReturn(D('ServiceApi')->getShopList($merchant_id));
	}
	
	/**
	 * @todo 返回店铺经营的一级品类
	 * @return array
	 * @author fzh <fanzhaohai@hrbjjhh.com>
	 */
	public function getGoodsCategoryPid($shop_id){
	    $goods_category = M('ShopGoodsCategoryShop')->where(array('shop_id'=>$shop_id))->field('goods_category_id')->select();
	    if(!empty($goods_category)){
	        $goods_category_id = array_column($goods_category,'goods_category_id');
            $this->ajaxReturn(D('ServiceApi')->getGoodsCategoryList($goods_category_id));
	    }else{
	        $this->ajaxReturn(array());
	    }
	}
	

	/**
	 * @todo 返回店铺经营的二级品类
	 * @return array
	 * @author fzh <fanzhaohai@hrbjjhh.com>
	 */
	public function getGoodsCategoryId($goods_category_id){
	    $goods_category_id = (int)$goods_category_id;
	    $this->ajaxReturn(D('ServiceApi')->getGoodsCategoryList($goods_category_id));
	}
	
	/**
	 * @todo ajax调取下级分类接口（文章分类）
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	Public function getAskCategory() {
	    $ask_category_id = (int)I('ask_category_id');//更新时ID值
	    $obj = D('ServiceApi');
	    $category_list = $obj->getAskCategoryTree();
	    if($ask_category_id>0 && isset($category_list[$ask_category_id])){
	        $ask_category_data = $category_list[$ask_category_id]['_child'];
	    }else{
	        $ask_category_data = null;
	    }
	    $this->ajaxReturn($ask_category_data);
	}
}
